/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.stripes.action;

import able.stripes.JSP;
import com.google.inject.Inject;
import exatrez.dao.ShipVisitHeaderDAO;
import exatrez.manager.ShipVisitFlowManager;
import exatrez.model.InfoAudit;
import exatrez.model.ShipVisitDescription;
import exatrez.model.User;
import exatrez.stripes.BaseActionBean;
import exatrez.stripes.config.AuthRequired;
import java.util.Date;
import java.util.List;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.hibernate.type.BlobType;
import org.hibernate.type.ClobType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Mansur
 */
@UrlBinding("/shipVisitDesc")
@AuthRequired
public class SvDescriptionAction extends BaseActionBean {
    private static Logger LOG = LoggerFactory.getLogger(SvDescriptionAction.class);
    
    @Inject
    ShipVisitFlowManager svFlowManager;
    @Inject
    ShipVisitHeaderDAO svHeaderDAO;
    
    private String id;
    private String hId;
    private String desc;
    private String sortNum;
    
    private List<ShipVisitDescription> listDesc;
    
    private static final String PAGE = "admin/sv_description.jsp";
    
    @DefaultHandler
    public Resolution main(){
        User user = getContext().getCurrentUser();
        listDesc = svFlowManager.listShipVisitDescription();
        return new JSP(PAGE);
    }
    
    public Resolution save(){
        User user = getContext().getCurrentUser();
        InfoAudit ia = new InfoAudit();
        ia.setCreateId(user);
        ia.setCreateDate(new Date());
        
        LOG.debug("ID :"+id);
        LOG.debug("hId :"+hId);
        LOG.debug("Desc :"+desc);
        LOG.debug("SortNum :"+sortNum);
        
        ShipVisitDescription svd = new ShipVisitDescription();
        svd.setSvDescId(id);
        svd.setSvHeaderId(svHeaderDAO.findById(hId));
        svd.setDescription(desc);
        svd.setSortNumber(Integer.parseInt(sortNum));
        svd.setInfoAudit(ia);
        String result = svFlowManager.saveorUpdateSVDesc(svd);
        if(result.equals("success")){
            addSimpleMessage("Success.");
        }else{
            addSimpleError("Error");
        }
        listDesc = svFlowManager.listShipVisitDescription();
        return new JSP(PAGE);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String gethId() {
        return hId;
    }

    public void sethId(String hId) {
        this.hId = hId;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getSortNum() {
        return sortNum;
    }

    public void setSortNum(String sortNum) {
        this.sortNum = sortNum;
    }  

    public List<ShipVisitDescription> getListDesc() {
        return listDesc;
    }

    public void setListDesc(List<ShipVisitDescription> listDesc) {
        this.listDesc = listDesc;
    }
}
